<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>注释</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="regexp.reference.conditional.html">« 条件子组</a></li>
      <li style="float: right;"><a href="regexp.reference.recursive.html">递归模式 »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="reference.pcre.pattern.syntax.html">PCRE 正则语法</a></li>
    <li>注释</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="regexp.reference.comments" class="section">
  <h2 class="title">注释</h2>
  <p class="para">
  字符序列(?#标记开始一个注释直到遇到一个右括号。不允许嵌套括号。
  注释中的字符不会作为模式的一部分参与匹配。
  </p>
  <p class="para">
  如果设置了 <a href="reference.pcre.pattern.modifiers.html" class="link">PCRE_EXTENDED</a> 选项，
  一个字符类外部的未转义的 # 字符就代表本行剩余部分为注释。
  </p>
  <p class="para">
   <div class="example" id="example-4721">
    <p><strong>示例 #1 PCRE 模式中注释的用法</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$subject&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'test'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/*&nbsp;(?#&nbsp;可用于添加注释而不启用&nbsp;PCRE_EXTENDED&nbsp;*/<br /></span><span style="color: #0000BB">$match&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">preg_match</span><span style="color: #007700">(</span><span style="color: #DD0000">'/te(?#&nbsp;this&nbsp;is&nbsp;a&nbsp;comment)st/'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$subject</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$match</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;除非启用&nbsp;PCRE_EXTENDED，否则空格和&nbsp;#&nbsp;视为模式的一部分&nbsp;*/<br /></span><span style="color: #0000BB">$match&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">preg_match</span><span style="color: #007700">(</span><span style="color: #DD0000">'/te&nbsp;&nbsp;&nbsp;#~~~~<br />st/'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$subject</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$match</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;启用&nbsp;PCRE_EXTENDED&nbsp;后，所有空白数据字符以及<br />&nbsp;&nbsp;&nbsp;同一行未转义的&nbsp;#&nbsp;后面的任何内容都将会忽略&nbsp;*/<br /></span><span style="color: #0000BB">$match&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">preg_match</span><span style="color: #007700">(</span><span style="color: #DD0000">'/te&nbsp;&nbsp;&nbsp;&nbsp;#~~~~<br />st/x'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$subject</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$match</span><span style="color: #007700">);</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
int(1)
int(0)
int(1)
</pre></div>
    </div>
   </div>
  </p>
 </div></div></div></body></html>